import sys
def P(num):
    if num <= 1:
        return False
    for i in range(2,int(num**0.5)+1):
        if num % i == 0:
            return False
    return True

def f(num):
    s = num - 1
    l = num + 1

    while True:
        if P(s):
            return s
        elif P(l):
            return l
        s -= 1
        l += 1

s=input("Введите слова на английском: ")
words = s.split()
s1 = words[0]
s2 = words[1]
s3 = words[2]
s11=0
s22=0
s33=0
if s1=="one" or s1=="two" or s1=="three" or s1=="four" or s1=="five" or s1=="six" or s1=="seven" or s1=="eight" or s1=="nine" or s1=="zero":
    if  s1=="one": 
        s11+=1
    if  s1=="two": 
        s11+=2
    if  s1=="three": 
        s11+=3
    if  s1=="four": 
        s11+=4
    if  s1=="five": 
        s11+=5
    if  s1=="six": 
        s11+=6
    if  s1=="seven": 
        s11+=7
    if  s1=="eight": 
        s11+=8
    if  s1=="nine":
        s11+=9
    if  s1=="zero": 
        s11+=0
else:
    print("Wrong input")
    sys.exit()
if s2=="one" or s2=="two" or s2=="three" or s2=="four" or s2=="five" or s2=="six" or s2=="seven" or s2=="eight" or s2=="nine" or s2=="zero":
    if  s2=="one": 
        s22+=1
    if  s2=="two": 
        s22+=2
    if  s2=="three": 
        s22+=3
    if  s2=="four": 
        s22+=4
    if  s2=="five": 
        s22+=5
    if  s2=="six": 
        s22+=6
    if  s2=="seven": 
        s22+=7
    if  s2=="eight": 
        s22+=8
    if  s2=="nine": 
        s22+=9
    if  s2=="zero": 
        s22+=0
else:
    print("Wrong input")
    sys.exit()
if s3=="one" or s3=="two" or s3=="three" or s3=="four" or s3=="five" or s3=="six" or s3=="seven" or s3=="eight" or s3=="nine" or s3=="zero":
    if  s3=="one": 
        s33+=1
    if  s3=="two": 
        s33+=2
    if  s3=="three": 
        s33+=3
    if  s3=="four": 
        s33+=4
    if  s3=="five": 
        s33+=5
    if  s3=="six": 
        s33+=6
    if  s3=="seven": 
        s33+=7
    if  s3=="eight": 
        s33+=8
    if  s3=="nine": 
        s33+=9
    if  s3=="zero": 
        s33+=0
else:
    print("Wrong input")
    sys.exit()
q = s11*100 + s22*10 + s33
z = f(q)
print(z)

